<template>
  <div class="app">
    <!-- 上半部分：固定区域 -->
    <div class="top-section">
      <h1>🎲 一家三口大富翁</h1>
      <!-- 骰子组件 -->
      <DiceRoller @rolled="onRolled" />
    </div>

    <!-- 下半部分：历史记录区域 -->
    <div class="history">
      <h3>历史记录</h3>
      <ul>
        <li v-for="(item, index) in history" :key="index">
          第 {{ history.length - index }} 次: {{ item }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import DiceRoller from './components/DiceRoller.vue'

const history = ref<number[]>([])

function onRolled(value: number){
  history.value.unshift(value)
}
</script>

<style scoped>
.app {
  text-align: center;
  padding: 0;
  font-family: "Microsoft YaHei", sans-serif;
  background: #f7f7f7;
  width: 100vw;
  height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  margin: 0;
  box-sizing: border-box;
  position: fixed;
  top: 0;
  left: 0;
}

.top-section {
  flex-shrink: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 50vh;
  min-height: 400px;
}

h1 {
  font-size: 24px;
  margin: 0 0 15px 0;
  color: #333;
  flex-shrink: 0;
}

button { 
  padding: 12px 20px; 
  margin-top: 10px; 
  font-size: 16px; 
  cursor: pointer; 
  border-radius: 8px;
  border: none;
  font-weight: 600;
}

.history {
  margin-top: 0;
  text-align: left;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
  padding: 15px 10px;
  width: 100%;
  height: 50vh;
  overflow-y: auto;
  background: #f7f7f7;
  border-top: 1px solid #ddd;
  flex-shrink: 0;
}

.history h3 {
  font-size: 18px;
  margin: 10px 0;
  color: #555;
}

.history ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.history li {
  padding: 8px 0;
  border-bottom: 1px dashed #ccc;
  font-size: 14px;
  color: #666;
}

/* 手机端适配 */
@media (max-width: 768px) {
  .top-section {
    padding: 15px;
    height: 45vh;
    min-height: 350px;
  }
  
  h1 {
    font-size: 20px;
    margin: 0 0 10px 0;
  }
  
  .history {
    max-width: 95%;
    height: 55vh;
    padding: 10px 8px;
  }
  
  .history h3 {
    font-size: 16px;
  }
  
  .history li {
    font-size: 13px;
    padding: 6px 0;
  }
}

@media (max-width: 480px) {
  .top-section {
    padding: 10px;
    height: 40vh;
    min-height: 300px;
  }
  
  h1 {
    font-size: 18px;
    margin: 0 0 8px 0;
  }
  
  .history {
    height: 60vh;
    padding: 8px 5px;
  }
  
  button {
    padding: 10px 16px;
    font-size: 14px;
  }
}
</style>
